package com.jmu.medicineknows.controller;

import com.jmu.medicineknows.dto.NewsDto;
import com.jmu.medicineknows.entity.NewsInfo;
import com.jmu.medicineknows.entity.Result;
import com.jmu.medicineknows.service.NewsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author ACER
 */
@Slf4j
@RestController
@RequestMapping("/news")
public class NewsController {

    @Resource
    private NewsService newsService;

    @PostMapping("/list")
    public Result newsList(@RequestBody NewsDto newsDto){
        log.info("newsDto = " + newsDto);
        return newsService.newsList(newsDto);
    }

    @PostMapping("/save")
    public Result save(@RequestBody NewsInfo newsInfo){
        return newsService.insertNews(newsInfo);
    }

    @DeleteMapping("/delete")
    public Result delete(@RequestBody NewsInfo newsInfo){
        return newsService.deleteNews(newsInfo);
    }

    @PutMapping("/update")
    public Result update(@RequestBody NewsInfo newsInfo){
        return newsService.updateNews(newsInfo);
    }

    @PostMapping("/livequery")
    public Result querryList(@RequestBody NewsDto newsDto){
        return newsService.selectNews(newsDto);
    }
}
